package com.era.act.com;

import org.apache.struts2.ServletActionContext;

import com.era.entity.Comment;
import com.era.srv.CommentSrv;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UpdateAction extends ActionSupport implements ModelDriven<Comment>{
	
	private CommentSrv commentSrv;
	
	public CommentSrv getCommentSrv() {
		return commentSrv;
	}



	public void setCommentSrv(CommentSrv commentSrv) {
		this.commentSrv = commentSrv;
	}
	private Comment comment = new Comment();
	
	@Override
	public Comment getModel() {
		// TODO Auto-generated method stub
		return comment;
	}



	public String show() throws Exception {
		Integer comId = comment.getComId();
		if(comId != null){
			comment = commentSrv.findById(comId);
			comment.setComId(comId);
			ServletActionContext.getRequest().getSession().setAttribute("commentUpdate", comment);
			return INPUT;
		}
		return ERROR;
	}
	public String update() throws Exception {
		comment = commentSrv.mergeComment(comment);
		return SUCCESS;
	}
}
